package dou;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;

public class clo {
    public static void main(String[] args) {
        new Thread(() -> {
            long tl = System.currentTimeMillis();
            while (true) {
                long ok = System.currentTimeMillis() - tl;
                if (ok >= 5 * 1000) break;
            }
            System.out.println("关机中");
        }).start();
        new Thread(() -> {
            String s = "2021-12-23 19:38:00";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            long end = 0;
            try {
                end = sdf.parse(s).getTime();
            } catch (ParseException e) {
                e.printStackTrace();
            }
            try {
                TimeUnit.MILLISECONDS.sleep(end - System.currentTimeMillis());
                Runtime.getRuntime().exec("cmd /c shutdown -s -t 0");
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.printf("%s 关机中*****", s);
        }).start();
    }
}
